package lysjmaster.base.auth.controller;

import lysjmaster.base.auth.domain.User;
import lysjmaster.base.auth.dto.UserConditionDTO;
import lysjmaster.base.auth.service.UserService;
import lysjmaster.base.common.spring.base.BaseController;
import lysjmaster.base.common.spring.base.BaseService;
import lysjmaster.base.common.spring.jpa.ConditionUtil;
import lysjmaster.base.common.spring.pagination.PageRequestDTO;
import lysjmaster.base.common.validation.annotation.Valid;
import lysjmaster.base.common.web.Resp;
import lysjmaster.base.common.web.RespUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Created by zk on 2019-12-04 14:28
 * @description
 */
@RestController
@RequestMapping("/auth/user")
public class UserController extends BaseController<User,UserConditionDTO> {
    @Resource
    private UserService userService;

    @Override
    public BaseService<User> getService() {
        return userService;
    }

    @PostMapping("/login")
    public Resp login(String username,String password){
        String token = userService.login(username, password);
        return RespUtil.success(token,"");
    }

    @PostMapping("/register")
    public Resp register(@Valid User user,String passwordConfirm){
        userService.saveUser(user,passwordConfirm);
        return RespUtil.success("用户注册成功");
    }

    @Override
    public Resp update(User entity) {
        userService.updateUser(entity);
        return RespUtil.success("修改成功");
    }

    @PostMapping("/reset_password")
    public Resp resetPassword(String id){
        userService.restPassword(id);
        return RespUtil.success("密码已重置为：123456，请尽快修改");
    }
}
